package web.suzy.oj.service.oj.impl;

import com.baomidou.mybatisplus.extension.plugins.pagination.Page;
import org.springframework.stereotype.Service;
import web.suzy.oj.common.exception.StatusFailException;
import web.suzy.oj.common.result.ResultBean;
import web.suzy.oj.manager.oj.ProblemManager;
import web.suzy.oj.pojo.vo.ProblemVO;
import web.suzy.oj.pojo.vo.RandomProblemVO;
import web.suzy.oj.service.oj.ProblemService;

import javax.annotation.Resource;
import java.util.List;

/**
 * YangSuzy 软件工作室
 * 类名: ProblemServiceImpl
 * 描述: ---- 待定 -----
 * 功能: ---- 待定 -----
 *
 * @author YangSuzy
 * Date: 2022/11/22 22:47
 */
@Service
public class ProblemServiceImpl implements ProblemService {
    @Resource
    private ProblemManager problemManager;

    /**
     * 方法名: getProblemList
     * 描述: 获取题目列表
     *
     * @param limit       每页显示数量
     * @param currentPage 当前页
     * @param keyword     关键字
     * @param tagId       标签ID
     * @param difficulty  难度
     * @return web.suzy.oj.common.result.ResultBean<com.baomidou.mybatisplus.extension.plugins.pagination.Page < web.suzy.oj.pojo.vo.ProblemVO>>
     * @date 2022/11/22 22:48
     * @auther YangSuzy
     **/
    @Override
    public ResultBean<Page<ProblemVO>> getProblemList(Integer limit, Integer currentPage, String keyword, List<Long> tagId, Integer difficulty) {
        return ResultBean.successResponse(problemManager.getProblemList(limit, currentPage, keyword, tagId, difficulty));
    }

    /**
     * 方法名: getRandomProblem
     * 描述: 随机获取一道题目
     *
     * @return web.suzy.oj.common.result.ResultBean<web.suzy.oj.pojo.vo.RandomProblemVO>
     * @date 2022/11/22 22:56
     * @auther YangSuzy
     **/
    @Override
    public ResultBean<RandomProblemVO> getRandomProblem() {
        try {
            return ResultBean.successResponse(problemManager.getRandomProblem());
        } catch (StatusFailException e) {
            return ResultBean.errorResponse(e.getMessage());
        }
    }
}
